#ifndef _IIC_H_
#define _IIC_H_

//
#define SDA_C	_pac0
#define SDA		_pa0

#define SCL_C   _pac2
#define SCL   	_pa2

#define DatHi()		SDA_C=1

#define	C_DEVICE_ID			0X70	//Slave Address  
#define	C_OPERATION_CMD		0X01	//Command word
#define	C_NC					0	

#define IIC_ERROR_NUM          10               //10 consecutive communication errors determine communication failure

// ErrorCode rang 0~15
typedef enum {	
	ERROR_NO			= (u8)0,	
	ERROR_UNDEFINE1		= (u8)1,
	ERROR_CIRCUIT		= (u8)2,
	ERROR_IGBT_OVER_TMP	= (u8)3,
	ERROR_IGBT_NTC		= (u8)4,
	ERROR_PAN_OVER_TMP	= (u8)5,
	ERROR_PAN_NTC		= (u8)6,
	ERROR_OCP			= (u8)7,
	ERROR_OVP			= (u8)8,
	ERROR_UVP			= (u8)9,
	ERROR_I2C 			= (u8)10,
	ERROR_COIL_OVERTMP	= (u8)11,
	ERROR_COIL_NTC		= (u8)12,
	ERROR_UNDEFINE2		= (u8)13,
	ERROR_UNDEFINE3		= (u8)14,
	ERROR_UNDEFINE4		= (u8)15,
} ErrorCode_TypeDef;


typedef enum {
	NO_PAN			= (bit)1,
	HAVE_PAN		= (bit)0
}CheckPan_TypeDef;	
	
	
typedef union
{
	struct
	{      		
	  vu8	pulseNum	:4;	
	  vu8	pulseWidth	:4;		
	}flagBit;    
	vu8 m_data;    
}PanDetSet_Flag;

typedef union
{
	struct
	{      		
	  vu8	IGBT_OVP	:3;	
	  vu8	undefine	:5;		
	}flagBit;    
	vu8 m_data;    
}ProtectSet_Flag;

typedef union
{
	struct
	{      		
	  vu8	PanOut_Current	:3;	
	  vu8	undefine		:5;		
	}flagBit;    
	vu8 m_data;    
}OtherSet_Flag;
	
extern bit bInitSet;
extern bit bInitSet_pulseNum,bInitSet_pulseWidth;
extern bit bInitSet_PanOut_Cur;

extern vu8 PowerStep_buf,TargetTemp_buf;	//Power and Temp
extern vu8 	PowerStep;
extern volatile IH_Status_FLAG IH_Status_App;
extern volatile ControlSet_Flag  ControlSet_App;

extern volatile PanDetSet_Flag	PanDetSet_App;
extern volatile ProtectSet_Flag	ProtectSet_App;
extern volatile OtherSet_Flag	OtherSet_App;
extern vu8 pulseNum_buf,pulseWidth_buf;
extern vu8 Igbt_ovp_buf;
extern vu8 panOut_Current_buf;



void IIC_Init();
void IIC_TimeOut();  //
void InitSetting_Handle();

#endif